package com.springboot.cloud.demos.feign.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.po.User;
import com.springboot.cloud.demos.feign.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
public class UnitController extends BaseController {

    @Autowired
    private UnitService unitService;


    @RequestMapping(value = "/open/unit", method = RequestMethod.GET)
    public Result unitWithOutLogin(HttpServletRequest request, @RequestParam String levelId) {
        Result<List<Map<String, Object>>> result = unitService.unit(levelId);
        return result;
    }

    @RequestMapping(value = "/unit", method = RequestMethod.GET)
    public Result unitLogin(HttpServletRequest request, @RequestParam String levelId) {
        User user = getUser(request);
        Result<List<Map<String, Object>>> result = unitService.queryByLevelAndUser(levelId, user.getId());
        return result;
    }

    @RequestMapping(value = "/open/unit/{id}", method = RequestMethod.GET)
    public Result level(@PathVariable(value = "id") String id) {
        return unitService.get(id);
    }

}
